package com.mike.layoutdemo415lbx;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;

public class FrameActivity extends AppCompatActivity {
    private ImageView imageView;
    private float downX,downY;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        imageView = findViewById(R.id.imageView2);
        imageView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        downX = event.getRawX();
                        downY = event.getRawY();
                        return true;
                    case  MotionEvent.ACTION_MOVE:
                        float deltaX = event.getRawX()-downX;
                        float deltaY = event.getRawY()-downY;

                        imageView.setTranslationX(imageView.getTranslationX()+deltaX);
                        imageView.setTranslationY(imageView.getTranslationY()+deltaY);

                        downX =event.getRawX();
                        downY =event.getRawY();

                        return true;

                    default:

                        return false;
                }

            }
        });
    }
}